home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / EDSTRWIN.C1 < prev    next >
Text File  |  1993-05-18  |  3KB  |  83 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville, MI
  3. Date: 05-15-93 (13:55)             Number: 160
  4. From: GAINES WRIGHT                Refer#: NONE
  5.   To: ZACH HANNA                    Recvd: NO  
  6. Subj: edstrwin() 1 of 3              Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. ZH>I am having serious difficulty writing a text input function.  I am
  9. ZH>limited in space, so I would like there to be a limit on the amount of
  10. ZH>characters which are displayed at one time, with arrows denoting wether
  11. ZH>or not there was text scrolled off either end.
  12.  
  13. ZH>Here is an example:
  14.  
  15. ZH>(Full string)      "This is just a sample text string"
  16. ZH>(Shown on screen)  .ust a sample tex.
  17.  
  18.   This is a quick hack of my edstrtxt() function to do the above.  Use
  19. at your own risk.
  20.                           Gaines Wright
  21.  
  22. //Written for TC by Gaines Wright
  23. //Donated to the public domain
  24.  
  25. #include <dos.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <conio.h>
  30. #include <mem.h>
  31. #include <ctype.h>
  32.  
  33. //Definitions for edstrwin() type parameter
  34. #define STRING 0  //Allows only alphanumeric.
  35. #define INT    1  //Allows only digits.
  36. #define FLOAT  2  //Allows only digits & one '.'.
  37. #define ONLY   3  //Allows only the chars contained in chars_allowed.
  38.  
  39. //Reads the keyboard.  Returns minus numbers for double char keys
  40. int getkey(void)
  41. {
  42. int c;
  43. if(!(c=getch()))
  44.   c=-getch();
  45. return(c);
  46. }
  47.  
  48. void beep(void)
  49. {
  50. sound(800);
  51. delay(10);
  52. nosound();
  53. }
  54.  
  55. //Edits a string at xpos, ypos, in a window winlen long, in the current text
  56. //attribute, accepts max_chars number of chars.  If using any type except
  57. //ONLY, *chars_allowed is not active.  Be sure when passing an empty string
  58. //for new input to do a string[0]='\0'; before calling or you will get
  59. //garbage on the screen.  Also do not allow the string to line wrap or the
  60. //editing keys will fail.
  61.  
  62. int edstrwin(char *string,int xpos,int ypos,int winlen,
  63.             int max_chars,int type,char *chars_allowed)
  64. {
  65. int c,strpos=0,str_len,beep_break;
  66. char *temp; //Holds the portion of string that appears in window
  67. if((temp=(char *)malloc(strlen(string)+1))==NULL)
  68.   {
  69.   cputs("Memory error in edstrwin()");
  70.   exit(-1);
  71.   }
  72. static char insert=0; //Change this to a 1 to start up in insert mode
  73. //continued next message
  74.  
  75. ---
  76.  ■ SLMR 2.1a ■ On a clear disk you can seek forever
  77.  
  78. --- DCI/Chauncy 0.7b
  79.  * Origin: Bird Lake - (813)265-3256 (1:377/14.0)
  80. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  81. SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
  82. SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  83.